<% add_decidim_page_title(t(".title")) %>
<div class="card" id="private_users">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t(".title") %>
      <% if allowed_to? :create, :space_private_user %>
        <%= link_to t(".publish_all"), publish_all_participatory_space_private_users_path(current_participatory_space), class: "button button__sm button__transparent-secondary publish-all", method: :post %>
        <%= link_to t(".unpublish_all"), unpublish_all_participatory_space_private_users_path(current_participatory_space), class: "button button__sm button__transparent-secondary unpublish-all", method: :post %>
        <%= link_to t(".import_via_csv"), new_participatory_space_private_users_csv_imports_path, class: "button button__sm button__transparent-secondary import" %>
        <%= link_to t("actions.participatory_space_private_user.new", scope: "decidim.admin"), url_for(action: :new), class: "button button__sm button__secondary new" %>
      <% end %>
    </h1>
  </div>
  <%= admin_filter_selector(:participatory_space_private_users) %>
  <% if participatory_space_private_users.any? %>
    <div class="table-stacked mt-4">
      <table class="table-list">
        <thead>
          <tr>
            <th>
             <%= sort_link(query, :name, t("models.user.fields.name", scope: "decidim.admin"), default_order: :desc ) %>
            </th>
            <th>
              <%= sort_link(query, :email, t("models.user.fields.email", scope: "decidim.admin"), default_order: :desc ) %>
            </th>
            <th>
              <%= sort_link(query, :published, t("models.user.fields.published", scope: "decidim.admin"), default_order: :desc ) %>
            </th>
            <th>
              <%= sort_link(query, :invitation_sent_at, t("models.user.fields.invitation_sent_at", scope: "decidim.admin"), default_order: :desc ) %>
            </th>
            <th>
              <%= sort_link(query, :invitation_accepted_at, t("models.user.fields.invitation_accepted_at", scope: "decidim.admin"), default_order: :desc ) %>
            </th>
            <th><%= t("decidim.admin.actions.actions") %></th>
          </tr>
        </thead>
        <tbody>
          <% participatory_space_private_users.each do |private_user| %>
            <tr>
              <td data-label="<%= t("models.user.fields.name", scope: "decidim.admin") %>">
                <%= private_user.user.name %>
              </td>
              <td data-label="<%= t("models.user.fields.email", scope: "decidim.admin") %>">
                <%= private_user.user.email %>
              </td>
              <td data-label="<%= t("models.user.fields.published", scope: "decidim.admin") %>">
                <% if private_user.published %>
                  <%= icon "check-line", class: "text-success" %>
                <% end %>
              </td>
              <td data-label="<%= t("models.user.fields.invitation_sent_at", scope: "decidim.admin") %>">
                <% if private_user.user.invitation_sent_at %>
                  <%= l private_user.user.invitation_sent_at, format: :short %>
                <% end %>
              </td>
              <td data-label="<%= t("models.user.fields.invitation_accepted_at", scope: "decidim.admin") %>">
                <% if private_user.user.invitation_accepted_at %>
                  <%= l private_user.user.invitation_accepted_at, format: :short %>
                <% end %>
              </td>
              <td data-label="<%= t("decidim.admin.actions.actions") %>" class="table-list__actions">
                <button type="button" data-controller="dropdown" data-target="actions-private-user-<%= private_user.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: private_user.user.name) %>">
                  <%= icon "more-fill", class: "text-secondary" %>
                </button>

                <div class="inline-block relative">
                  <ul id="actions-private-user-<%= private_user.id %>" class="dropdown dropdown__action" aria-hidden="true">
                    <% if allowed_to?(:edit, :space_private_user, private_user: private_user) %>
                      <li class="dropdown__item">
                        <%= link_to edit_participatory_space_private_user_path(current_participatory_space, private_user), class: "dropdown__button" do %>
                          <%= icon "pencil-line" %>
                          <%= t("actions.edit", scope: "decidim.admin") %>
                        <% end %>
                      </li>

                      <hr>
                    <% end %>

                    <% if allowed_to?(:invite, :space_private_user, private_user: private_user) && private_user.user.invited_to_sign_up? %>
                      <li class="dropdown__item">
                        <%= link_to resend_invitation_participatory_space_private_user_path(current_participatory_space, private_user), method: :post, class: "dropdown__button" do %>
                          <%= icon "refresh-line" %>
                          <%= t("actions.resend_invitation", scope: "decidim.admin") %>
                        <% end %>
                      </li>

                      <hr>
                    <% end %>

                    <% if allowed_to?(:destroy, :space_private_user, private_user: private_user) %>
                      <li class="dropdown__item">
                        <%= link_to participatory_space_private_user_path(current_participatory_space, private_user), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                          <%= icon "delete-bin-line" %>
                          <%= t("actions.destroy", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% end %>
                  </ul>
                </div>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
    <%= decidim_paginate participatory_space_private_users %>
  <% end %>
</div>
